#ifndef _INCLUDE_IOQUEUE_H_
#define _INCLUDE_IOQUEUE_H_

#include "stdint.h"
#include "sync.h"
#include "thread.h"
#define BUF_SIZE 64

struct ioqueue
{
  struct mutex_t      lock;
  struct task_struct* producer_blocked;
  struct task_struct* consumer_blocked;
  char                buf[BUF_SIZE];
  ///@brief Head index for data write
  int32_t head;
   ///@brief Tail index for data read
  int32_t tail;
};

void ioqueue_init(struct ioqueue* queue);

char ioqueue_getchar(struct ioqueue* queue);

void ioqueue_putchar(struct ioqueue* queue,char byte);

/**
 * @brief
 *
 * @param waiter_thread
 */
void ioqueue_wait(struct task_struct** waiter_thread);

void ioqueue_wake_up(struct task_struct** waiter_thread);

int32_t ioqueue_next_pos(int32_t cur_pos);

bool ioqueue_is_full(struct ioqueue* queue);

bool ioqueue_is_empty(struct ioqueue* queue);

#endif // !_INCLUDE_IOQUEUE_H_
